package com.sxt;

import java.awt.*;

public class Bg {
    static int level = 1;
    int goal = level*15;
    static int count=0;
    static int waterNum=3;
    static boolean waterFlag = false;
    long startTime;
    long endTime;
    int price = (int) (Math.random()*10);
    boolean shop=false;
    Image bg = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
    Image bg1 = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
    Image peo = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
    Image water = Toolkit.getDefaultToolkit().getImage("imgs/water.png");

    void paintSelf(Graphics g){
        g.drawImage(bg1,0,0,null);
        g.drawImage(bg,0,200, null);
        switch (GameWin.state){
            case 0:
                drawWord(g,80,Color.green,"准备开始",170,400);
                drawWord(g,40,Color.black,"说明：",150,500);
                drawWord(g,40,Color.blue,"右键开始",170,600);
                drawWord(g,40,Color.blue,"开始后左键抓取，右键使用药水",170,700);
                break;
            case 1:
                g.drawImage(peo, 310, 50,null);
                drawWord(g,30,Color.black,"积分："+count,30,150);
                g.drawImage(water,450,40,null);
                drawWord(g,30,Color.black,"*"+waterNum,510,70);
                drawWord(g,20,Color.black,"第"+level+"关",30,60);
                drawWord(g,30,Color.black,"目标："+goal,30,110);
                endTime = System.currentTimeMillis();
                long tim = 20-(endTime-startTime)/1000 ;
                drawWord(g,30,Color.black,"时间"+(tim>0?tim:0),520,150);
                break;
            case 2:
                g.drawImage(water,300,400,null);
                drawWord(g,30,Color.black,"当前积分："+count,300,300);
                drawWord(g,30,Color.black,"价格："+price,300,500);
                drawWord(g,30,Color.black,"是否购买？"+waterNum,300,550);
                if(shop){
                    count = count-price;
                    waterNum++;
                    shop=false;
                    GameWin.state=1;
                    startTime=System.currentTimeMillis();
                }
                break;
            case 3:
                drawWord(g,80,Color.cyan,"失败"+goal,250,350);
                drawWord(g,80,Color.cyan,"积分："+count,200,450);
                break;
            case 4:
                drawWord(g,80,Color.red,"成功"+goal,250,350);
                drawWord(g,80,Color.red,"积分："+count,200,450);
                break;
            default:
        }
    }

    boolean gameTime(){
        long tim=(endTime-startTime)/1000;
        if(tim>20){return true;}
        return false;
    }

    void reGame() {
        level = 1;
        goal = level*15;
        count=0;
        waterNum=3;
        waterFlag = false;
    }
    public static void drawWord(Graphics g, int size, Color color,String str, int x, int y){
        g.setColor(color);
        g.setFont(new Font("仿宋",Font.BOLD,size));
        g.drawString(str,x,y);
    }
}